#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn = 40010;
char names[maxn][5];
bool cmp(int &a, int &b)
{
    return strcmp(names[a], names[b]) < 0;
}
int main()
{
    int n, k, id;
    vector<int> course[maxn];
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++)
    {
        int num, tc;
        scanf("%s %d", names[i], &num);
        for (int j = 0; j < num; j++)
        {
            scanf("%d", &tc);
            course[tc].push_back(i);
        }
    }
    for (int i = 1; i <= k; i++)
    {
        sort(course[i].begin(), course[i].end(), cmp);
        printf("%d %d\n", i, course[i].size());
        for (int j = 0; j < course[i].size(); j++)
            printf("%s\n", names[course[i][j]]);
    }
    return 0;
}